package com.cn.controller;

import com.cn.RedisThread.Redis_Set_WorksComment;
import com.cn.entity.Works;
import com.cn.mapper.Works.WorksMapper;
import com.cn.service.Imp.WorkServiceImp;
import com.cn.vo.WorksVo.Comment;
import com.cn.vo.WorksVo.Like;
import com.cn.vo.WorksVo.Report;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName WorkController
 * @Description TODO
 * @Author yujiajing
 * @Date 2022/12/19 20:35
 * @Version 1.0
 */
@CrossOrigin(origins = "*")
@RestController
public class WorkController {
    @Autowired
    Like like;
    @Autowired
    Redis_Set_WorksComment redis_set_worksComment;
    @Autowired(required = false)
    WorkServiceImp workServiceImp;
    @Autowired(required = false)
    WorksMapper worksMapper;
    @RequestMapping("/publishWorks")
    public String publishWorks(Works works) {
       workServiceImp.publishWorks(works);
        return "作品发布成功!";
    }
    @RequestMapping("/showAllWorks")
    public Object showWorks(){
        return worksMapper.selectList(null);
    }

    @RequestMapping("/editComment")
    public String comment(Comment comment) {
        workServiceImp.writeComment(comment);
        return "评论成功！";
    }
    @RequestMapping("/showComment")
    public Object showComment() {
//        redis_set_worksComment.start();
        return workServiceImp.showAllComments();
    }

    @RequestMapping("/showCommentByAdmin")
    public Object showCommentByAdmin(String userName) {
        return workServiceImp.showAllCommentByAdmin(userName);
    }

@RequestMapping("/showLike")
    public  Object showLike(){
      return   workServiceImp.showLike();
}
    @RequestMapping("/like")
    public String like(Like like) {
        workServiceImp.giveLike(like);
        return "点赞成功！";

    }
    @RequestMapping("/deleteLike")
    public String deleteLike(int worksId,String likeName){
        workServiceImp.deleteLike(worksId,likeName);
        return  "取消点赞成功";
    }
    @RequestMapping("giveReport")
    public String giveReport(Report report){
        workServiceImp.giveReport(report);
        return "举报成功";
    }
    @RequestMapping("showReport")
    public List<Report> showReport(){
      return   workServiceImp.showReport();
    }
}